package com.linux.huhx.thread3.holdcount_1;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Author: huhx
 * @Date: 2017-10-31 上午 8:41
 */
public class Service {
    private ReentrantLock lock = new ReentrantLock();

    public void serviceMethod1() {
        try {
            System.out.println("before service method 1 getHoldCount = " + lock.getHoldCount());
            lock.lock();
            System.out.println("after service method 1 getHoldCount = " + lock.getHoldCount());
            serviceMethod2();
        } finally {
            lock.unlock();
        }
    }

    public void serviceMethod2() {
        try {
            System.out.println("before service method 2 getHoldCount = " + lock.getHoldCount());
            lock.lock();
            System.out.println("after service method 2 getHoldCount = " + lock.getHoldCount());
        } finally {
            lock.unlock();
        }
    }
}
